<template>
  <div class="chatmsg" ref="msg">
    <div v-for="(item, index) in lists" :key="index">
      <div :class="item.type == true ? 'user' : 'touser'">
        <div>
          <img :src="item.face" alt />
          <div :class="item.type == true ? 'bubble' : 'tobubble'">
            <span>{{ item.word }}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { reactive } from "vue";

export default {
  name: "chat-msg",
  setup() {
    const lists = reactive([]);
    return {
      lists,
    };
  },
};
</script>

<style scoped lang="scss">
.chatmsg {
  position: relative;
  top: 0;
  width: 100%;
  min-height: 0.1rem;
  background-color: rgb(238, 212, 238);
  overflow-x: hidden;
  overflow-y: auto;
  .user {
    position: relative;
    width: 100%;
    overflow: hidden;
    font-size: 0;
    img {
      object-fit: cover;
      width: 1rem;
      height: 1rem;
      border-radius: 0.2rem;
      float: right;
      margin-left: 0.2rem;
    }

    .bubble {
      position: relative;
      float: right;
      margin-right: 0.1rem;
      padding: 0.08rem;
      box-sizing: border-box;
      border-radius: 3px;
      max-width: 65%;
      background-color: rgb(116, 228, 116);
      font-size: 0rem;
      span {
        font-size: 0.16rem;
        height: 0.125rem;
        line-height: 0.125rem;
      }
    }

    .bubble::after {
      position: absolute;
      right: -0.13rem;
      top: 0.08rem;
      content: "";
      width: 0;
      height: 0;
      border: 0.07rem solid;
      border-color: transparent transparent transparent rgb(116, 228, 116);
    }
  }
  .touser {
    position: relative;
    width: 100%;
    overflow: hidden;
    font-size: 0;
    img {
      object-fit: cover;
      width: 0.3rem;
      height: 0.3rem;
      border-radius: 3px;
      float: left;
      margin-left: 0.1rem;
    }
    .tobubble {
      position: relative;
      float: left;
      padding: 0.08rem;
      box-sizing: border-box;
      border-radius: 3px;
      max-width: 65%;
      background-color: #fff;
      font-size: 0rem;
      margin-left: 0.1rem;
      span {
        font-size: 0.16rem;
        height: 0.125rem;
        line-height: 0.125rem;
      }
    }
    .tobubble::after {
      position: absolute;
      left: -0.13rem;
      top: 0.08rem;
      content: "";
      width: 0;
      height: 0;
      border: 0.07rem solid;
      border-color: transparent #fff transparent transparent;
    }
  }
}
</style>
